
/// <reference path="Component.js" />
/// <reference path="_namespace.js" />
/// <reference path="../drawing/Colour.js"/>

/*****************************************************************************
Ajax library class definition. Kevin Robinson 2007.
Class: ajax.components.ColorPicker

This class implements a showColorDialog method which will return a rrggbb color value.
This class instance also maintains a .Color attribute.
/*****************************************************************************/

ajax.lang.addNamespace("ajax.components");
//$imports("ajax.drawing.Colour");

//-----------------------------------------------------------------------------
ajax.components.ColorPicker = function(doc) // Constructor
{    
    ajax.components.ColorPicker.superConstructor.apply(this, arguments);
    this._colour = null;    
}

ajax.lang.extend("ajax.components.ColorPicker", "ajax.components.Component"); // Inherits
if ($getDesignMode())
    ajax.components.ColorPicker.prototype = ajax.components.Component.prototype;

ajax.components.ColorPicker.prototype._colour = null;// ajax.drawing.Colour.prototype;
ajax.components.ColorPicker.prototype.get_colour = function() 
{/// <returns type="ajax.drawing.Colour"/>
    return this._colour; 
}
ajax.components.ColorPicker.prototype.set_colour = function(value) 
{/// <param name="value" type="ajax.drawing.Colour">A colour value</param> 
    this._colour = value; 
} 


//-----------------------------------------------------------------------------
ajax.components.ColorPicker.prototype.showColorDialog = function(initColor)
{///<returns type="ajax.drawing.Colour">Returns the color picked</returns>
    // Try to get a handle to the helper object. If not then create one.
    var helper = $(this.getDocument(), "dlgHelper");
    if (!helper)
    {
        helper = this.getDocument().createElement("object");
        helper.id = "dlgHelper";
        helper.classid = "clsid:3050f819-98b5-11cf-bb82-00aa00bdce0b";
        try
        {        
            helper.style.position = "absolute";
            helper.style.left = helper.style.top = -640;
            helper.width = helper.height = "0px";
        }
        catch(ex)
        {}
        
        this.getDocument().body.appendChild(helper);        
    }
    //call the dialog box and initialize the color to the color previously chosen
    var sColor = helper.ChooseColorDlg(initColor);

    //change the return value from a decimal value to a hex value and make sure the value has 6
    //digits to represent the RRGGBB schema required by the color table
    sColor = sColor.toString(16);
    if (sColor.length < 6)
    {
        var sTempString = "000000".substring(0, 6 - sColor.length);
        sColor = sTempString.concat(sColor);
    }

    this.set_colour(ajax.drawing.Colour.fromHex(sColor));
    return this.get_colour();
}

//-----------------------------------------------------------------------------
ajax.components.ColorPicker.prototype.toString = function()
{
    return "ajax.components.ColorPicker";
}

//-----------------------------------------------------------------------------
ajax.components.ColorPicker.cast = function(obj)
{///<returns type="ajax.components.ColorPicker"/>
    return obj
}